package com.whalehearing.tingyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;
import com.whalehearing.tingyou.mapper.HearingDetailedQuestionnaireMapper;
import com.whalehearing.tingyou.domain.HearingDetailedQuestionnaire;
import com.whalehearing.tingyou.service.IHearingDetailedQuestionnaireService;

/**
 * 详细问卷Service业务层处理
 *
 * @author zengjun-qxm
 * @date 2024-09-20
 */
@Service
public class HearingDetailedQuestionnaireServiceImpl extends ServiceImpl<HearingDetailedQuestionnaireMapper, HearingDetailedQuestionnaire> implements IHearingDetailedQuestionnaireService {

    @Autowired
    private HearingDetailedQuestionnaireMapper hearingDetailedQuestionnaireMapper;

    /**
     * 查询详细问卷列表
     *
     * @param hearingDetailedQuestionnaire 详细问卷
     * @return 详细问卷
     */
    @Override
    public List<HearingDetailedQuestionnaire> selectHearingDetailedQuestionnaireList(HearingDetailedQuestionnaire hearingDetailedQuestionnaire)
    {
        List<HearingDetailedQuestionnaire> hearingDetailedQuestionnaireList = hearingDetailedQuestionnaireMapper.selectList(buildQueryWrapper(hearingDetailedQuestionnaire));
        return hearingDetailedQuestionnaireList;
    }


    private LambdaQueryWrapper<HearingDetailedQuestionnaire> buildQueryWrapper(HearingDetailedQuestionnaire query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<HearingDetailedQuestionnaire> lqw = Wrappers.lambdaQuery();
        lqw.eq(query.getUserId() != null, HearingDetailedQuestionnaire::getUserId, query.getUserId());
        lqw.orderByDesc(HearingDetailedQuestionnaire::getCreateTime);
        return lqw;
    }

    /**
     * 根据-userId-查询用户详细问卷详细信息
     */
    @Override
    public List<HearingDetailedQuestionnaire> getHearingDetailedQuestionnaireByUserId(Long userId) {

        QueryWrapper<HearingDetailedQuestionnaire> queryWrapper = new QueryWrapper<HearingDetailedQuestionnaire>()
                .eq("user_id", userId);

        return hearingDetailedQuestionnaireMapper.selectList(queryWrapper);
    }

}
